package com.adams.access.db.bean;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * 
 * 
 * File Name : Entity.java
 * 
 * @Description : 所有实体类的基类，统一定义id的属性名称、数据类型、列名映射及生成策略
 */
@MappedSuperclass
public abstract class EntityObject implements Serializable, java.lang.Cloneable
{

	private static final long serialVersionUID = 1L;

	protected Long id;

	protected int version;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	public Long getId()
	{
		return id;
	}

	public void setId(Long id)
	{
		this.id = id;
	}

	@Version
	@Column(name = "VERSION")
	public int getVersion()
	{
		return version;
	}

	public void setVersion(int version)
	{
		this.version = version;
	}

	@Override
	public String toString()
	{
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.MULTI_LINE_STYLE);
	}

	@Override
	public boolean equals(Object o)
	{
		return o != null && o.getClass().equals(this.getClass())
				&& EqualsBuilder.reflectionEquals(this, o);
	}

	// @Override
	// public int hashCode()
	// {
	// return HashCodeBuilder.reflectionHashCode(this);
	// }
}
